package com.college.collegeinfomanage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.college.collegeinfomanage.dto.AcademicProgramsDTO;
import com.college.collegeinfomanage.entity.AcademicPrograms;
import com.college.collegeinfomanage.service.AcademicProgramsService;
import com.college.collegeinfomanage.util.Result;
import com.college.collegeinfomanage.vo.AcademicProgramsListVO;
import com.college.collegeinfomanage.vo.UniversityListVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RestController
@RequestMapping("/academicPrograms")
public class AcademicProgramsController {

    @Resource
    private AcademicProgramsService academicProgramsService;

    @GetMapping("/university/all")
    public Result universityAll(){
        List<UniversityListVO> universityListVOs = academicProgramsService.universityAll();
        return Result.success(universityListVOs);
    }

    @PostMapping("/academic/add")
    public Result add(@RequestBody AcademicPrograms academicPrograms){
        boolean save = academicProgramsService.save(academicPrograms);
        return save ? Result.success("添加成功") : Result.fail("添加失败");
    }

    @GetMapping("/academic/list")
    public Result page(AcademicProgramsDTO academicProgramsdto){
        IPage<AcademicProgramsListVO> page = academicProgramsService.getPage(academicProgramsdto);
        return Result.success(page);
    }

    @PutMapping("/academic/update")
    public Result update(@RequestBody AcademicPrograms academicPrograms){
        boolean update = academicProgramsService.modify(academicPrograms);
        return update ? Result.success("修改成功") : Result.fail("修改失败");
    }

    @DeleteMapping("/academic/delete/{id}")
    public Result delete(@PathVariable Integer id){
        boolean removeById = academicProgramsService.removeById(id);
        return removeById ? Result.success("删除成功") : Result.fail("删除失败");
    }
}
